package com.wuhongyu.service.impl;

import com.wuhongyu.base.BaseServiceImpl;
import com.wuhongyu.entity.Record;
import com.wuhongyu.repository.CustomerDao;
import com.wuhongyu.repository.RecordDao;
import com.wuhongyu.service.RecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("recordService")
public class RecordServiceImpl extends BaseServiceImpl<Record> implements RecordService {

    @Autowired
    private CustomerDao customerDao;
    private RecordDao recordDao;

    @Resource
    public void setDao(RecordDao recordDao){
        super.setBaseDao(recordDao);
        this.recordDao = recordDao;
    }

    @Override
    public List<Record> findAll(Integer customerid){
        return recordDao.findByCustomerEquals(customerDao.getOne(customerid));
    }

    @Override
    public void save(Record record) {
        record.setCustomer(customerDao.getOne(record.getCustomer().getId()));
        recordDao.saveAndFlush(record);
    }

}